import { betModel, towerModel } from '@/types/model'
import { AbstractDraw } from './AbstractDraw'

export class DrawSpan extends AbstractDraw {
  constructor(ctx: CanvasRenderingContext2D, startY: number, private towers: towerModel[], private bets: betModel[]) {
    super(ctx, startY)
  }

  public draw() {
    for (const bet of this.bets) {
      const [n1, n2] = bet.btName.split('--')
      const t1 = this.towers.find((t) => t.tName === n1)
      const t2 = this.towers.find((t) => t.tName === n2)
      const [x1, y1] = [t1?.leiSpan! / 5, -6 + this.startY]
      const [x2, y2] = [t2?.leiSpan! / 5, -6 + this.startY]
      super.drawline(super.scaleXY(x1, y1), this.scaleXY(x2, y2), 1.5, '#7f8c8d')

      // 绘制第一基塔的横线
      if (this.bets.indexOf(bet) === 0)
        super.drawline(super.scaleXY(x1, y1 - 3), super.scaleXY(x1, y1 + 3), 1.5, '#7f8c8d')
      super.drawline(super.scaleXY(x2, y2 - 3), super.scaleXY(x2, y2 + 3), 1.5, '#7f8c8d')

      // 绘制档距文字
      const cen = t2?.leiSpan! / 2 / 5 + t1?.leiSpan! / 2 / 5
      const [cx, cy] = [cen, -20 + this.startY]
      const txt = bet.btSpan
      super.drawText(txt.toString(), this.scaleXY(cx, cy), '#7f8c8d')
    }
  }
}
